#pragma once

#include <iostream>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <unordered_map>
#include <functional>

typedef std::function<void()> func;

std::vector<func> callbacks;
std::unordered_map<int, std::string> desc;

void readMySQL()
{
    std::cout << "Sub process[" << getpid() << "] execute the task of visiting DataBase.\n" << std::endl;
}

void analyseUrl()
{
    std::cout << "Sub process[" << getpid() << "] execute the task of analysing Url.\n" << std::endl;
}

void saveData()
{
    std::cout << "Sub process[" << getpid() << "] execute the task of saving data.\n" << std::endl;
}

void calculateNum()
{
    std::cout << "Sub process[" << getpid() << "] execute the task of calculating number.\n" << std::endl;
}

void load()
{
    desc.insert({callbacks.size(), "readMySQL:visiting DataBase."});
    callbacks.push_back(readMySQL);
    desc.insert({callbacks.size(), "analyseUrl:analysing Url."});
    callbacks.push_back(analyseUrl);
    desc.insert({callbacks.size(), "saveData:saving data."});
    callbacks.push_back(saveData);
    desc.insert({callbacks.size(), "calculateNum:calculating number."});
    callbacks.push_back(calculateNum);
}

void showHandler()
{
    for (const auto &iter : desc) {
        std::cout << iter.first << "\t" << iter.second << std::endl;
    }
}

int handlerSize()
{
    return callbacks.size();
}
